<template>
	<view class="map-container">
		<div id="map" style="height: 400px; width: 100%;"></div>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: "",
				url:"",
				id:"",
			}
		},
		onLoad(options) {
			console.log('传递过来的参数',options)
			this.type = options.type;
			this.id = options.id;
			let language = uni.getStorageSync('language') || 'en';
			this.url = `/hybrid/html/maps/map.html?type=${this.type}&id=${this.id}&language=${language}`;
			console.log(this.url)
			// window.addEventListener("message", this.onMessage, false); //监听事件
		},
		mounted() {
			this.initMap();
		},
		methods: {
			initMap(e) {
				debugger
				// if (typeof window.google !== 'undefined' && window.google.maps) {
				const location = { lat: -34.397, lng: 150.644 }; // 初始位置
				const map = new window.google.maps.Map(document.getElementById("map"), {
					zoom: 8,
					center: location,
				});

				const marker = new window.google.maps.Marker({
					position: location,
					map: map,
				});
				// } else {
				// console.error('Google Maps API not loaded');
				// }
			},
			onMessage(res) {
				console.log('传递过来参数222',res.data.data) //web页面传过来的参数
				let location = res.data.data;
				if(location.name=="postMessage"){
					uni.setStorageSync('location', location.arg);
				}
			},
			onPostMessage(e){
				console.log('postMessage请求参数',e)
			}
		}
	}
</script>

<style lang="less" scoped>
	.box {}
</style>